package com.bytz.modules.cms.product.service.impl;

import com.bytz.modules.cms.product.entity.ProductHierarchy;
import com.bytz.modules.cms.product.model.ProductModel;
import com.bytz.modules.cms.product.service.IMallProductHierarchyService;
import com.bytz.modules.cms.product.service.IProductHierarchyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class MallProductHierarchyServiceImpl implements IMallProductHierarchyService {

    @Autowired
    private IProductHierarchyService productHierarchyService;

    @Override
    public void setHierarchyLevelInfo(List<ProductModel> modelList) {

        List<String> hierrarchNumbers = modelList.stream().map(ProductModel::getHierarchyNumber).collect(Collectors.toList());
        Map<String, ProductHierarchy> hierarchyMap = productHierarchyService.getByHierarchyNumbers(hierrarchNumbers).stream()
                .collect(Collectors.toMap(ProductHierarchy::getHierarchyNumber, e -> e));

        modelList.forEach(productModel -> {
            ProductHierarchy hierarchy = hierarchyMap.get(productModel.getHierarchyNumber());
            productModel.setPrepayRatio(hierarchy.getPrepayRatio());
//            productModel.setDeliveryDate(hierarchy.getDeliveryTime());
        });
    }

}